//
//  DropViewController.m
//  etionRichText
//
//  Created by wangjian on 11/18/13.
//
//

#import "DropViewController.h"

@interface CDropViewController ()

@end

@implementation CDropViewController
{
    UIView *_bgView;
    CGRect _startFrame;
    UIView *_contentFrameView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)showContentViewWithStartFrame:(CGRect)startFrame Complete:(void (^)(void))complete
{
    _startFrame = startFrame;
    UIView *rootView = [[UIApplication sharedApplication].delegate window].rootViewController.view;
    self.view.frame = rootView.bounds;
    [rootView addSubview:self.view];
    
    _bgView = [[[UIView alloc] initWithFrame:self.view.bounds] autorelease];
    _bgView.backgroundColor = [UIColor grayColor];
    _bgView.alpha = 0.0;
    [self.view addSubview:_bgView];
    
    _contentFrameView = [[[UIView alloc] initWithFrame:startFrame] autorelease];
    _contentFrameView.clipsToBounds = YES;
    [self.view addSubview:_contentFrameView];
    
    [_contentFrameView addSubview:self.contentView];
    self.contentView.frame = CGRectMake(0, 0, self.contentView.width, self.contentView.height);
    _contentFrameView.alpha = 0.5;
    [UIView animateWithDuration:0.25f delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        _bgView.alpha = .5;
        _contentFrameView.frame = CGRectMake((self.view.width-self.contentView.width)/2, (self.view.height-self.contentView.height)/2, self.contentView.width, self.contentView.height);
        _contentFrameView.alpha = 1.0;
    } completion:^(BOOL finished) {
        complete();
    }];
}

- (void)hideContentViewComplete:(void (^)(void))complete
{
    [UIView animateWithDuration:0.25f delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        _bgView.alpha = 0.0;
        _contentFrameView.frame = _startFrame;
        _contentFrameView.alpha = 0.5;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        complete();
    }];
}

- (void)dealloc
{
    [_contentView release];
    [super dealloc];
}

@end
